package com.mitcub.panda.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @项目名称: panda
 * @类名称: AdminLoginConfig
 * @类描述: 配置虚拟路径映射 拦截
 * @作者: tangloong
 * @创建时间: 2021/7/22 17:19
 */

@Configuration
public class AdminLoginConfig implements WebMvcConfigurer {

    private static final String UPLOADED_FOLDER = System.getProperty("user.dir");
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/uploads/**")
                .addResourceLocations("file:///" + UPLOADED_FOLDER + "/uploads/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册TestInterceptor拦截器
        InterceptorRegistration registration = registry.addInterceptor(new AdminInterceptor());
        registration.addPathPatterns("/**");                      //所有路径都被拦截
        registration.excludePathPatterns(                         //添加不拦截路径
                "/login/**",             //登录相关
                "/register/**",         //注册 激活
                "/api/**",              //小程序接口api
                "/error/**",
                "/asset/**",            //静态资源
                "/favicon.ico",         //静态资源
                "/uploads/**"           //上传文件
        );
    }
}
